# 1.python回炉
# 2.向量编程思维
# 3.pandas处理表格
# 4.输入输出还是文件读写

# print(3)
# print('Hello world')
# print(3.14)

# a = 1
# b = 2.4
# c = 'abcdefg'
#
# print(a)
# print(b)
# print(c)

# 1+1
# 321324*64546
# a = 1 + 1
# print(a)
# b = 3 * 6
# print(b)
#
# c = a + b
# print(c)
# print(a, '+', b, '=', c)
# print(f'{a} + {b} = {c}')  # f-string
# print('{} + {} = {}'.format(a, b, c))

# a = 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
# print(a)
#
# total = 0
# for i in range(100):
#     total = total + 1
# print(total)
#
# print(sum([1 for _ in range(100)]))

# total = 0
# for i in range(1, 101):  # [a, b)
#     total = total + i
# print(total)

# total = 0
# for i in range(1, 34):
#     total = total + i*3
# print(total)
#
# total = 0
# for i in range(1, 101):
#     for j in range(int(i % 3 == 0)):
#         total = total + i
# print(total)
#
# total = 0
# for i in range(1, 101):
#     if i % 3 == 0:
#         total = total + i
# print(total)

# a = 42343543
# if a % 3 == 1:
#     print('3n + 1')
# elif a % 3 == 2:
#     print('3n + 2')
# else:
#     print('3n')
#
#
# if a % 3 == 1:
#     print('3n + 1')
# else:
#     if a % 3 == 2:
#         print('3n + 2')
#     else:
#         print('3n')
#
#
# print('3n + 1') if a % 3 == 1 else print('3n + 2') if a % 3 == 2 else print('3n')
#
# b = 'a is big' if a > 10000 else 'a is small'  # a?b:c
# print(b)
# if a > 10000:
#     b = 'a is big'
# else:
#     b = 'a is small'
#
# print(b)

# a = int(input('a is: >'))
# print('a is big') if a > 10000 else print('a is small')

# *
# **
# ***
# ****
# *****
# ******
# *******
# ********
#
# for row in range(8):
#     for col in range(row + 1):
#         print('*', end='')
#     print()
#
# print()
#
# for row in range(8):
#     print('*'*(row+1), end='')
#     print()
#
# print()
# *
# **
# ***
# ****
# *****
# ******
# *******
# ********
# *
# **
# ***
# ****
# *****
# ******
# *******
# ********

# for times in range(2):
#     for row in range(8):
#         print('*' * (row + 1), end='')
#         print()


# def eight_lines():
#     for row in range(8):
#         print('*' * (row + 1))
#
# eight_lines()


# def p_stars(k):
#     print('*' * (row + 1), end='')
#     print()
#
#
# for times in range(2):
#     for row in range(8):
#         p_stars(row)
#

def say_hello(name='Tom'):
    print(f'Hello {name}!')


# say_hello('Jim')
# say_hello()


def run_time(func):
    import time

    def wrap_func(*args, **kwargs):
        t0 = time.time()
        result = func(*args, **kwargs)
        t1 = time.time()
        print(f'Function {func.__name__!r} executed in {(t1 - t0):.6f}s')
        return result
    return wrap_func


say_hello_time = run_time(say_hello)
# say_hello_time()
# say_hello_time('Susan')


@run_time  # 修饰器
def say_goodbye(name='Tom'):
    print(f'Goodbye: {name}!')


# say_goodbye()
# say_goodbye('Lucy')


@run_time
def factorial(n):  # 递归
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)


@run_time
def fibonacci(n):
    if n == 1 or n == 2:
        return 1
    else:
        return fibonacci(n-1) + fibonacci(n-2)


# print(factorial(10))
# print(fibonacci(10))


# https://docs.python.org/3/library/functools.html
from functools import lru_cache


@lru_cache
@run_time
def fib(n):
    if n == 1 or n == 2:
        return 1
    else:
        return fib(n-1) + fib(n-2)


# print(fib(100))


# a = [1, 3, 6, 10]
# for i in a:
#     print(i)
#
#
# # a = 1
# # b = 2
# # a, b = b, a
# # (a, b) = (b, a)
#
#
# for i, v in enumerate(a):
#     print(i, v)
#
#
# a = [1, 3, 6, 'OK']
# for i in a:
#     print(i)
# print(type(a))
#  list tuple dict

# a = (1, 3, 6, 10)
# print(type(a))
# a = (1, 3, 6, 'OK')
# print(type(a))

# a = {'name': 'Tom', 'ID': 102, 'Tel': '10110210310'}
# for k in a:
#     print(k, a[k])
# for k in a.keys():
#     print(k)
# for v in a.values():
#     print(v)
# for k, v in a.items():
#     print(k, v)

# # print(1/0)
# try:
#     a = 1/0
# except:
#     a = 0
# print(a)


# class Obj:
#     def __init__(self, l):
#         self.l = l
#
#     def get_l(self):
#         return self.l
#
#     def set_l(self, l):
#         self.l = l
#
#
# pencil = Obj(0.2)
# print(pencil.l)
# pencil.set_l(0.15)
# print(pencil.l)


# # A(m,n) B(n,l)
# # C=AB
# # C_ij = sum_k A_ik*Bkj
# def prod(A, B):
#     C = [[]]
#     for i in range(m):
#         for j in range(l):
#             C[i][j] = 0
#             for k in range(n):
#                 C[i][j] = A[i][k] * B[k][j]
